package com.usoft10;

import akka.actor.ActorRef;
import akka.actor.ActorSystem;
import akka.actor.Props;

public class Example {
    /**
     * @param args
     */
    public static void main(String[] args) throws InterruptedException {
        ActorSystem _system = ActorSystem.create("CustomRouterExample");
        ActorRef burstyMessageRouter = _system.actorOf(Props.create(
                MsgEchoActor.class).withRouter(new BurstyMessageRouter(5)), "MsgEchoActor");

        /**
         * 在这里模拟发出10个消息，使用RoundRobinRoutingLogic的router会轮询调度每个actor接收消息
         * 也就是说每次tell，router只会选择其中一个actor进行消息的响应
         */
        for (int i = 1; i <= 10; i++) {
            //sends series of messages in a round robin way to all the actors
            burstyMessageRouter.tell("are you ready?" + String.valueOf(i), ActorRef.noSender());
        }

        Thread.sleep(2000);
        _system.shutdown();
    }

}
